home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Help with writing floating points numbers to strings
- Date: 14 Mar 1996 21:27 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <14MAR199621272391@erich.triumf.ca>
- References: <4ia9g9$d1f@yama.mcc.ac.uk>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4ia9g9$d1f@yama.mcc.ac.uk>, Simon Letherman <simon@ma.man.ac.uk> writes...
-
- >I want to write output to a large string, which I can then get Mathematica
- >to use to draw a graph. Unfortunately, this means that I've got to store
- >floating point (actually double) variables in string format, and it
- >really doesn't want to. I can usually get my code past the preprocessor,
- >but when running anything like
- > sprintf(string, "%lf", &double);
- >I get the core dumped on me.
-
- use
- sprintf(string, "%f", double);
-
- A float argument passed to (s|f)printf() is automatically promoted to double,
- so there is no distinction between float and double - %f is used to print
- either. %lf is an error (but may be accepted bu some lenient compilers...)
-
- Your real problem was the "&double" - you don't want the "&". printf() wants
- to get the variables themselves, not their addresses.
-
- The parameters to scanf() and printf() are similar, but not identical!
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-